<?
include("common/header.html");
include("common/page.php");
include("common/left.html");
include('common/func.inc.php');
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
if(!$_SESSION['memberID']){
    exit("<script>window.location='dlogin.html'</script>");
}
$sid=$_SESSION['sid'];
$did= intval($_REQUEST["did"]);

if (!$did) {
    echo <<<SCRIPT
    <script>
    alert('请选择分销商！');history.go(-1);
    </script>
SCRIPT;
    exit;
}

$currentPage = $_GET["currentPage"]?intval($_GET["currentPage"]):1;
$pageSize    = $_GET['pageSize']?intval($_GET["pageSize"]):20;
$offset      = ($currentPage-1)*$pageSize;

$sec=$op=$tpl=$prod_list=array();
$sel="select dname from pft_member where id=$did LIMIT 1";
$GLOBALS['le']->query($sel);
$GLOBALS['le']->fetch_assoc();
$dname=$GLOBALS['le']->f("dname");

//获取配置过的价格
$sel=<<<SQL
SELECT tid,dprice FROM uu_priceset WHERE
(aid=0 OR aid={$_SESSION['sid']}) AND pid=$did ORDER BY aid ASC
SQL;
$GLOBALS['le']->query($sel);
while($row=$GLOBALS['le']->fetch_assoc()){
    $op[$row['tid']]=$row['dprice'];
}
//print_r($op);
//exit;
$sel="select tplid from uu_fx_tpl_cs where fxid=$did LIMIT 1";
$GLOBALS['le']->query($sel);
$GLOBALS['le']->fetch_assoc();
$tplid=$GLOBALS['le']->f("tplid");
$where = "p.p_status in (0,3) and p.apply_limit=1 and p.apply_did={$sid}";
$limit = "LIMIT $offset, $pageSize";
if (!empty($_GET['prodname'])) {
    $limit = '';
    $prodname = urldecode($_GET['prodname']);
    $where .= " AND p_name LIKE '%{$prodname}%'";
}

$sql_total = "SELECT count(*) as cnt FROM uu_products p WHERE {$where}";

$GLOBALS['le']->query($sql_total);
$GLOBALS['le']->fetch_assoc();
$total = $GLOBALS['le']->f('cnt');

$sel = <<<SQL
  SELECT p.id,p.contact_id as lid,p.apply_did,p.p_name FROM uu_products p WHERE {$where}
  order by p.id DESC $limit
SQL;
//echo $sel;
//exit;
//$limit
if($_GET['debug']){
    echo $sel;
}
$GLOBALS['le']->query($sel);
$date_now = date("Y-m-d");

while($row=$GLOBALS['le']->fetch_assoc()){
    //取供货价
    $pri=$s->get_Dynamic_Price_Merge($row['id'],$date_now,1);
    if($pri==-1){
        $pri=$s->get_Dynamic_Price_Merge($row['id'],$date_now,2);
    }
    //|| $row['apply_did']!=$sid
    if($pri==-1 ){
        continue;
    }
    else{
        $row['fp']=$pri/100;
    }
    $prod_list[$row['id']]=$row;
}

if (count($prod_list)) {
    $pid_str = implode(',', array_keys($prod_list));
    //已配置的直销产品数据
    $evo_data = array();
    $sel=<<<SQL
SELECT pid,aids,lvl,sid,sourceid FROM pft_p_apply_evolute
WHERE sid=$sid AND fid=$did AND pid IN($pid_str) AND lvl=1 AND status=0
SQL;
//    echo $sel;
    $GLOBALS['le']->query($sel);
    while($row=$GLOBALS['le']->fetch_assoc()){
        $evo_data[$row['pid']] = $row;
    }
    $sec = array_keys($evo_data);
}

if($_GET['debug']){
    print_r($prod_list);
    print_r($sec);
}
include("tpl/priceset_dev.html");
include("common/footer.html");?>